package leetcode;

import java.util.Arrays;

/**
 * @author wangmaolin1
 * @date 2023/11/16 21:08
 */
public class _1288 {
    public int removeCoveredIntervals(int[][] intervals) {
        Arrays.sort(intervals,(a,b)->{
            if (a[0] == b[0]){
                return b[1]-a[1];
            }
            return a[0]-b[0];
        });
        int start = intervals[0][0];
        int end = intervals[0][1];
        int res=0;
        for (int i = 1; i < intervals.length; i++) {
            if (intervals[i][0]>=start && intervals[i][1]<=end){
                res++;
            }
            if (end>=intervals[i][0] &&end<= intervals[i][1]){
                end = intervals[i][1];
            }
            if(end<=intervals[i][0]){
                start=intervals[i][0];
                end=intervals[i][1];
            }
        }
        return intervals.length- res;
    }
}
